package cn.tj212.xiaoyin.opt.controller;

import cn.tj212.xiaoyin.common.page.TailPage;
import cn.tj212.xiaoyin.common.storage.QiniuStorage;
import cn.tj212.xiaoyin.core.course.domain.CourseComment;
import cn.tj212.xiaoyin.core.course.service.ICourseCommentService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/courseComment")
public class CourseCommentController {

    @Autowired
    private ICourseCommentService courseCommentService;

    @RequestMapping("/pagelist")
    public ModelAndView commentSegment(CourseComment queryEntity, TailPage<CourseComment> page){
        ModelAndView mv=new ModelAndView("cms/course/readComment");
        queryEntity.setCourseId(1L);
        TailPage<CourseComment> commentTailPage = this.courseCommentService.queryPage(queryEntity,page);
        //处理用户头像
        for (CourseComment item:commentTailPage.getItems()
             ) {
            if (StringUtils.isNotEmpty(item.getHeader())){
                item.setHeader(QiniuStorage.getUrl(item.getHeader()));
            }
        }
        mv.addObject("page",commentTailPage);
        mv.addObject("queryEntity",queryEntity);
        return mv;
    }
}
